#!/bin/bash
#---------------------- order_notice ----------------------
notice=$(pgrep -f 'php think order_notice')

if [ "$notice" ]; then
  if
    [ ${#notice[@]} -gt 0 ]
  then
    echo 'php think order_notice 正在运行 共有'${#notice[*]}'个进程'
    echo "进程列表 $notice"
    for i in $notice; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think order_notice 未运行 即将运行'
    nohup php think order_notice &
  fi
else
  echo 'php think order_notice 未运行 即将运行'
  nohup php think order_notice &
fi


#---------------------- order_end ----------------------
order_end=$(pgrep -f 'php think order_end')

if [ "$order_end" ]; then
  if
    [ ${#order_end[@]} -gt 0 ]
  then
    echo 'php think order_end 正在运行 共有'${#order_end[*]}'个进程'
    echo "进程列表 $order_end"
    for i in $order_end; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think order_end 未运行 即将运行'
    nohup php think order_end &
  fi
else
  echo 'php think order_end 未运行 即将运行'
  nohup php think order_end &
fi

#---------------------- order_out ----------------------
order_out=$(pgrep -f 'php think order_out')

if [ "$order_out" ]; then
  if
    [ ${#order_out[@]} -gt 0 ]
  then
    echo 'php think order_out 正在运行 共有'${#order_out[*]}'个进程'
    echo "进程列表 $order_out"
    for i in $order_out; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think order_out 未运行 即将运行'
    nohup php think order_out &
  fi
else
  echo 'php think order_out 未运行 即将运行'
  nohup php think order_out &
fi

#---------------------- order_validity ----------------------
order_validity=$(pgrep -f 'php think order_validity')

if [ "$order_validity" ]; then
  if
    [ ${#order_validity[@]} -gt 0 ]
  then
    echo 'php think order_validity 正在运行 共有'${#order_validity[*]}'个进程'
    echo "进程列表 $order_validity"
    for i in $order_validity; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think order_validity 未运行 即将运行'
    nohup php think order_validity &
  fi
else
  echo 'php think order_validity 未运行 即将运行'
  nohup php think order_validity &
fi

#---------------------- extension_end ----------------------
extension_end=$(pgrep -f 'php think extension_end')

if [ "$extension_end" ]; then
  if
    [ ${#extension_end[@]} -gt 0 ]
  then
    echo 'php think extension_end 正在运行 共有'${#extension_end[*]}'个进程'
    echo "进程列表 $extension_end"
    for i in $extension_end; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think extension_end 未运行 即将运行'
    nohup php think extension_end &
  fi
else
  echo 'php think extension_end 未运行 即将运行'
  nohup php think extension_end &
fi

#---------------------- extension_validity ----------------------
extension_validity=$(pgrep -f 'php think extension_validity')

if [ "$extension_validity" ]; then
  if
    [ ${#extension_validity[@]} -gt 0 ]
  then
    echo 'php think extension_validity 正在运行 共有'${#extension_validity[*]}'个进程'
    echo "进程列表 $extension_validity"
    for i in $extension_validity; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think extension_validity 未运行 即将运行'
    nohup php think extension_validity &
  fi
else
  echo 'php think extension_validity 未运行 即将运行'
  nohup php think extension_validity &
fi

#---------------------- extension_notice ----------------------
extension_notice=$(pgrep -f 'php think extension_notice')

if [ "$extension_notice" ]; then
  if
    [ ${#extension_notice[@]} -gt 0 ]
  then
    echo 'php think extension_notice 正在运行 共有'${#extension_notice[*]}'个进程'
    echo "进程列表 $extension_notice"
    for i in $extension_notice; do
      kill -9 "$i"
      echo "杀死进程 $i"
    done
  else
    echo 'php think extension_notice 未运行 即将运行'
    nohup php think extension_notice &
  fi
else
  echo 'php think extension_notice 未运行 即将运行'
  nohup php think extension_notice &
fi

sleep 2s
ps aux | grep php |grep -v grep
